#!/usr/bin/python

import sys
from optparse import OptionParser

class Zviera(object):
  def __init__(self):
    self.num_heads = 1
    self.num_tails = None
    self.num_legs = None
    self.fur_color = None
    self.name = None
    self.sound = None

  def Describe(self):
    return ('My name is %s, color of my fur is %s. I have %r legs, %r tails'
    ' and %r heads.' %(self.name, self.fur_color,self.num_legs, self.num_tails,
                     self.num_heads))
  
  def MakeSound(self):
    return 'Robim zvuk %s' %(self.sound)

#zadefinuj fuknciu a presun vsetky if statementy a vsetky instancie do tejto novej funkcie:P     

def InstantiateAndExecute(options):
  """It should create all instances of all classes based on optparse function and then returns them."""  
#Najpr si zadefinujem vystupy, este pred zadavanim podmienok, nech mi to nevyhodi UnBoundLocalError : referenced before assigment  
###HOMEWORKENZI : Vyries si problem s errorom a 2. nech sa mi neopakuju call na make_sound a describe = urob si s tym nieco .

  if options.animal == 'Macka':
    if options.name == 'Fluffy':
      macka_obj = Macka(options.name, 'white')
      make_sound_str = macka_obj.MakeSound()
      describe_str = macka_obj.Describe()
      specific_str = macka_obj.Spi()   
    elif options.name == 'Blackie':
      macka_obj = Macka(options.name, 'black')
      make_sound_str = macka_obj.MakeSound()
      describe_str = macka_obj.Describe()
      specific_str = macka_obj.Spi()   
    else:
      raise NotImplementedError('Macka s takymto menom nepatri do nasho zverica :)')
  elif options.animal == 'Pes' and options.name == 'Dunco':
      pes_obj = Pes(options.name, 'brown')
      make_sound_str = pes_obj.MakeSound()
      describe_str = pes_obj.Describe()
      specific_str = pes_obj.Dones()   
  elif options.animal == 'Had' and options.name == 'Sykacka':
      had_obj = Had(options.name, 'i do not have a fur')
      make_sound_str = had_obj.MakeSound()
      describe_str = had_obj.Describe()
      specific_str = had_obj.PlazSa()   
  elif options.animal == 'Kohut' and options.name == 'Kikirikac':
      kohut_obj = Kohut(options.name, 'perie')
      make_sound_str = kohut_obj.MakeSound()
      describe_str = kohut_obj.Describe()
      specific_str = None
  else:
    raise NotImplementedError('Taketo zviera nie je v nasom zverinci :)')
  
  return (describe_str, make_sound_str, specific_str)
# ak atribut animal vo vstupe funkcii InstantiateAndExecute m= stringu s obsahom Macka
# tak mas urobit toto : 
# 1.VYtvori instanciu objektu Macka
# 2.spusti funkcie spolocne pre all = describe a makesound
# 3.spusti specificke funkcie len pre macku
# 4.vrat toto vsetko ako tuple stringov ()
#  print dunco == Pes('Dunco','brown')
#  sound = dunco.MakeSound()
#  return sound
#  if options.animal == 'Macka' and options.name =='Fluffy':
#   print Fluffy
#  elif options.animal == 'Macka' and options.name == 'Blackie':
#    Blackie = Macka('Blackie','black')
#  elif options.animal == 'Macka' and options.name is None:
#    Fluffy = Macka('Fluffy','white')
#    Blackie = Macka('Blackie','black')
#  elif options.animal == 'Macka' and options.name != 'Blackie' or options.name != 'Fluffy':
#  elif options.animal == 'Pes':
#    Dunco = Pes('Dunco' , 'brown')
# elif options.animal == 'Kohut':
#   Kikirik = Kohut('Kikirik', '... well i do not have a fur at all :] ')
# elif options.animal == None and options.name == None:
#   Fluffy = Macka('Fluffy','white')
#   Blackie = Macka('Blackie','black')
#   Dunco = Pes('Dunco' , 'brown')
#   Kikirik = Kohut('Kikirik', '... well i do not have a fur at all :] ')
#   Sykacka = Had('Sykacka')


class Macka(Zviera):
  def __init__(self,name, fur_color):
    super(Macka,self).__init__()
    self.num_tails = 1
    self.num_legs = 4
    self.fur_color = fur_color
    self.name = name
    self.sound = 'mnaw'
  def Spi(self):
    return 'Spim'
    
class Pes(Zviera):
  def __init__(self,name,fur_color):
    super(Pes, self).__init__()
    self.num_tails = 1
    self.num_legs = 4
    self.fur_color = fur_color
    self.name = name
    self.sound = 'hav'
  def Dones(self):
    return 'Nech sa paci'

class Kohut(Zviera):
  def __init__(self,name, fur_color):
    super(Kohut,self).__init__()
    self.num_tails = 1
    self.num_legs = 2
    self.fur_color = fur_color
    self.name = name
    self.sound = 'kikiriki'

class Had(Zviera):
  def __init__(self,name, fur_color):
    super(Had,self).__init__()
    self.num_tails =None 
    self.num_legs = None
    self.fur_color = 'i do not have a fur'
    self.name = name
    self.sound = 'sss'
  def PlazSa(self):
    return 'Plazim sa'


def main():
#dest.'animal' => vytvor atribut, ktory sa bude vola animal  

  parser = OptionParser()
  parser.add_option('--animal' , type ='string' , dest='animal')
  parser.add_option('--name' , type ='string' , dest='name')
  (options, unused_args) = parser.parse_args()


  try:
    (describe_str, make_sound_str, specific_str) = InstantiateAndExecute(options)
  except NotImplementedError, e:
    print e
    sys.exit(1)

  print describe_str
  print make_sound_str
  print specific_str


#    print StatementFunkcia(options)
#    print fluffy.Describe()
#    print fluffy.MakeSound()
#    Fluffy = Macka('fluffy','white')
#    print Fluffy.Describe()
#    print Fluffy.MakeSound()
#    print Fluffy.Spi() 
#    print '\n'
#    print Blackie.Describe()
#    print Blackie.MakeSound()
#    print Blackie.Spi()
#    print '\n'
#    print Fluffy.Describe()
#    print Fluffy.MakeSound()
#    print Fluffy.Spi() 
#    print '\n'
#    print Blackie.Describe()
#    print Blackie.MakeSound()
#    print Blackie.Spi()
#    print '\n'
#    print Dunco.Describe()
#    print Dunco.Dones()
#    print '\n'
#    print Kikirik.Describe()
#    print '\n'
#    print Fluffy.Describe()
#    print Fluffy.MakeSound()
#    print Fluffy.Spi()
#    print '\n'
#    print Blackie.Describe()
#    print Blackie.MakeSound()
#    print Blackie.Spi()
#    print '\n'
#    print Dunco.Describe()
#    print Dunco.Dones()
#    print '\n'
#    print Kikirik.Describe()
#    print '\n'
#    print Sykacka.Describe()
#    print Sykacka.MakeSound()
#    print '\n'

if __name__ == '__main__':
  main()
